'/
' GUI Library
' Written by Anton Berlin, 2010.
' 
' =========================================================================
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published
' by the Free Software Foundation; either version 3 of the License.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU Lesser General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'/

superstrict

import "../../framework/keycodes/keycodes.bmx"
import "../strutil/strutil.bmx"

import "GUI_Gadget.bmx"

type GUI_Text extends GUI_Gadget

	'// -------------------------------------------------------------------------------------------------------------
	'// Draw this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method draw()
	
		if (not m_visible) ..
			return;
		
		'// Setup the default drawing settings.
		drawutil.setColorInit(m_primitiveR, m_primitiveG, m_primitiveB);
		drawutil.setAlphaInit(m_transparency);
		drawutil.setFontInit(null);
		
		'// Draw the design of the gadget.
		design();
		
		'// Reset drawing settings.
		drawutil.resetColor();
		drawutil.resetAlpha();
		drawutil.resetFont();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Draw the design of this gadget.
	'// -------------------------------------------------------------------------------------------------------------
	method design()
	
		setImageFont(m_font);
		
		local text:string;
		local y:int = m_posY;
		local yOffset:int = textHeight(m_text) + 2;
		
		for local index:int = 0 until strutil.words(m_text, KEY_DOLLAR)
		
			text = strutil.word(index, m_text, KEY_DOLLAR);
			
			'// Shadow.
			if (m_useShadows) then
			
				setAlpha(m_transparency * 0.5);
				setColor(0, 0, 0);
				drawText(text, m_posX + 3, y + yOffset * index + 3);
			
			end if
			
			'// Upper border.
			if (m_useBorders) then
			
				setAlpha(m_transparency * 1.0);
				setColor(m_borderColorR, m_borderColorG, m_borderColorB)
				drawText(text, m_posX, y + yOffset * index);
				
				'// Lower border.
				setColor(m_borderColorR, m_borderColorG, m_borderColorB)
				drawText(text, m_posX + 2, y + yOffset * index + 2);
			
			end if
			
			'// Main text.
			setColor(m_primaryColorR, m_primaryColorG, m_primaryColorB)
			drawText(text, m_posX + 1, y + yOffset * index + 1);
		
		next
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the color to use on the text.
	'// -------------------------------------------------------------------------------------------------------------
	method setPrimaryColor(r:int, g:int, b:int)
	
		m_primaryColorR = r;
		m_primaryColorG = g;
		m_primaryColorB = b;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the color to use on the "border" surrounding the text.
	'// -------------------------------------------------------------------------------------------------------------
	method setBorderColor(r:int, g:int, b:int)
	
		m_borderColorR = r;
		m_borderColorG = g;
		m_borderColorB = b;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the text to use.
	'// -------------------------------------------------------------------------------------------------------------
	method setText(str:string)
	
		m_text = str;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set the font to use.
	'// -------------------------------------------------------------------------------------------------------------
	method setFont(font:TImageFont)
	
		m_font = font;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use shadows on the text.
	'// -------------------------------------------------------------------------------------------------------------
	method setTextShadowUsage(value:byte)
	
		m_useShadows = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Set whether or not to use borders on the text.
	'// -------------------------------------------------------------------------------------------------------------
	method setTextBorderUsage(value:byte)
	
		m_useBorders = value;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Returns the width in pixels of the text.
	'// -------------------------------------------------------------------------------------------------------------
	method getTextWidth:short()
	
		drawutil.setFontInit(m_font);
		local width:short = textWidth(m_text);
		drawutil.resetFont();
		return width;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Returns the height in pixels of the text.
	'// -------------------------------------------------------------------------------------------------------------
	method getTextHeight:short()
	
		drawutil.setFontInit(m_font);
		local height:short = textHeight(m_text);
		drawutil.resetFont();
		return height;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The color to use on the text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_primaryColorR:int;
	field m_primaryColorG:int;
	field m_primaryColorB:int;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The color to use on the "border" surrounding the text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_borderColorR:int;
	field m_borderColorG:int;
	field m_borderColorB:int;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The text to use.
	'// -------------------------------------------------------------------------------------------------------------
	field m_text:string;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to use shadows on the text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useShadows:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Flag that determines whether or not to use borders on the text.
	'// -------------------------------------------------------------------------------------------------------------
	field m_useBorders:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The font to use.
	'// -------------------------------------------------------------------------------------------------------------
	field m_font:TImageFont;

end type

